<?php
// +----------------------------------------------------------------------
// | Created by PHPstorm: [ JRK丶Admin ]
// +----------------------------------------------------------------------
// | Copyright (c) 2019~2022 [LuckyHHY] All rights reserved.
// +----------------------------------------------------------------------
// | SiteUrl: http://www.luckyhhy.cn
// +----------------------------------------------------------------------
// | Author: LuckyHhy <jackhhy520@qq.com>
// +----------------------------------------------------------------------
// | Date: 2020/7/30 0030
// +----------------------------------------------------------------------
// | Description: 百度推送
// +----------------------------------------------------------------------

namespace app\admin\controller\push;


use app\common\controller\AdminBaseController;
use app\common\library\Push;


class Baidu extends AdminBaseController
{

    protected function initialize()
    {
        parent::initialize(); // TODO: Change the autogenerated stub

    }


    public function index(){

        return $this->fetch();
    }


    /**
     * @throws \think\Exception
     * @throws \think\exception\PDOException
     * @author: LuckyHhy <jackhhy520@qq.com>
     * @name: zhanzhang
     * @describe: 提交
     */
    public function zhanzhang(){
        if (IS_POST){
            $action = $this->request->post("action");
            $urls = $this->request->post("urls");

            $urls = explode("\n", $urls);
            $urls = array_unique(array_filter($urls));
            if (!$urls) {
                $this->error("URL列表不能为空");
            }
            $result = false;
            if ($action == 'urls') {
                $result = Push::init(['type' => 'zhanzhang'])->realtime($urls);
            } elseif ($action == 'del') {
                $result = Push::init(['type' => 'zhanzhang'])->delete($urls);
            }
            if ($result) {
                $data = Push::init()->getData();
                $this->success("推送成功", null, $data);
            } else {
                $this->error("推送失败：" . Push::init()->getError());
            }
        }
    }

}